﻿Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Channels.Http
Imports TfsSearchCode
Imports System.Runtime.Remoting.Activation

Module Module1

    Sub Main(ByVal cmdArgs() As String)

        Dim iCanal As Integer = 7080
        Dim sIP As String = "localhost"
        ' See if there are any arguments.
        If cmdArgs.Length > 0 Then
            For argNum As Integer = 0 To UBound(cmdArgs, 1)
                cmdArgs(argNum) = cmdArgs(argNum).ToUpper
                If cmdArgs(argNum).Contains("CANAL:") Then
                    iCanal = Val(Mid(cmdArgs(argNum), cmdArgs(argNum).IndexOf("CANAL:") + 7))
                End If
                If cmdArgs(argNum).Contains("IP:") Then
                    sIP = Mid(cmdArgs(argNum), cmdArgs(argNum).IndexOf("IP:") + 4)
                End If
            Next argNum
        End If

        sIP = "http://" & sIP & ":" & CStr(iCanal)
        Dim sIPUri As String = sIP & "/object1uri"
        Dim sIPClass As String = sIP & "/TFSSearchCodeClass"

        Console.WriteLine(sIP)

        '
        ' Client activated type: the object is instanting on server, but is passed to client, 
        ' each clienthave a particular instancve of object and determines the live of object
        ' by thechnical supports based on spondsor objects whos renews the life of objects.

        RemotingConfiguration.RegisterActivatedClientType( _
           GetType(TFSSearchCodeClass), _
            sIPClass)





        ' Registers the remote class. (This could be done with a
        ' configuration file instead of a direct call.)

        'RemotingConfiguration.RegisterWellKnownClientType(GetType(TFSSearchCodeClass), sIPUri)
        'RemotingConfiguration.RegisterWellKnownClientType(Type.GetType("TfsSearchCodeClass, TfsSearchCode"), sIPDefinitiva)

        ' Instead of creating a new object, this obtains a reference
        ' to the server's single instance of the ServiceClass object.


        Try
            Dim object1 As TFSSearchCodeClass = New TFSSearchCodeClass()
            Dim object2 As TFSSearchCodeClass = New TFSSearchCodeClass()

            Console.WriteLine("Computer " & object1.GetComputerName(True))
            Console.WriteLine("Computer " & object2.GetComputerName(True))
            Console.WriteLine("Computer " & object1.GetComputerName(True))
            Console.WriteLine("Computer " & object2.GetComputerName(True))
            Console.ReadKey()

            Try
                object1.Connect("login", "pass", "http://81.00.2.2:8080")


                'AddHandler object1.ProgressSearchingFolders, AddressOf EventoCliente
                'object1.FireEvent()

                '                object1.ProgressAssign(AddressOf EventoCliente)
                'object1.SearchTextInCode("$/Alfavb6/desarrollo/aplicaciones/alma", "*.*", "Alma")

                object1.LoadFoldersOnTFsServer("$/")
                Dim st() As String = object1.Folders
                Dim col2 As List(Of ItemSource) = object1.ItemsSource
                Console.ReadKey()
            Catch ex As Exception
                MsgBox(ex.Message.ToString)

            End Try



        Catch ex As Exception
            Console.WriteLine("Exception of type: " & ex.GetType.ToString & " occurred.")
            Console.WriteLine("Details: " & ex.Message)
        End Try


    End Sub

    Public Sub EventoCliente(ByVal p As Integer)
        Console.WriteLine("client knows callback: {p} completed", p)
    End Sub

End Module
